﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using servermon_library;

namespace servermon
{
	public partial class RemServerWindow : Form
	{
		private RadioButton[] buttons;
		private ServerManager manager;
		private Main main;

		public RemServerWindow(ServerManager _manager, Main mainwindow)
		{
			InitializeComponent();

			manager = _manager;
			main = mainwindow;

			Server[] servers = manager.GetServers();
			buttons = new RadioButton[servers.Length];
			Int16 counter = 0;
			foreach (Server server in servers)
			{
				buttons[counter] = new RadioButton();
				buttons[counter].Text = server.servername;
				buttons[counter].Name = Convert.ToString(server.serverid);
				flpContent.Controls.Add(buttons[counter]);
				counter++;
			}
		}

		private void btnRemove_Click(object sender, EventArgs e)
		{
			RadioButton selectedButton = new RadioButton();
			foreach (RadioButton button in buttons)
			{
				if (button.Checked == true)
				{
					selectedButton = button;
					break;
				}

			}
			try
			{
				manager.RemoveServer(Convert.ToInt32(selectedButton.Name));
				main.window_Update();
				this.Close();
			}
			catch (Exception)
			{
				MessageBox.Show("Please select a server you want to delete from the list first!");
			}
		}
	}
}
